home *** CD-ROM | disk | FTP | other *** search
- #include "MST_Defines.h"
- #include "MST_Externs.h"
- #include "MST_Prototypes.h"
-
-
- /*_____________________________________________________________________________
- Init_Windows()- set all the window pointers to NIL
- _____________________________________________________________________________*/
-
-
- void Init_Windows (void)
- {
- AboutMSTDlog = NIL;
- PeriodicChartDlog = NIL;
- ElementsDlog = NIL;
- }
-
-
- /*_____________________________________________________________________________
- Activate_Window()- handle activate events
- _____________________________________________________________________________*/
-
-
-
- void Activate_Window (WindowPtr thisWindow)
- {
- GDHandle saveDevice;
- CGrafPtr saveCGraphPtr;
-
- GetGWorld (&saveCGraphPtr,&saveDevice); /*We just need to know the device*/
- /*so we can pass the info to*/
- /*SetGWorld later*/
- /*
- • We determine which window we are working with by examining the window's
- • reference constant. The reference constant (called the RefCon) is a
- • four byte field in the window's data structure which is available for
- • the programmer to use. Often programmers store a handle to a custom
- • structure which stores data associated with the window (such as editable
- • text and style information for a word processor). In this program, we have
- • stored the resource ID number of the dialog template in the RefCon field of the
- • dialog template, and use it to distinguish what kind of window (About,
- • Periodic, or Element) we are working with. Other methods abound. In some
- • cases it might make sense to use the window's title. In others, you
- • might store a unique identifier along with other data in a structure
- • you access via a handle you store in the window's RefCon. Keep in mind
- • also the following. Most operations on windows of the same "category" will
- • work the same, which will greatly simplify your program. For example, if
- • we consider "document" windows of a word processor as a category, only a
- • single update routine, a single save routine, etc are required for the
- • category, regardless of the number of open windows.
- */
- switch (GetWRefCon(thisWindow))
- {
- case ResID_AboutMST:
- case ResID_PeriodicChart:
- case ResID_Elements:
- {
- /*
- • Make Quickdraw's current port your window you are activating.
- */
- SetGWorld ((CGrafPtr)thisWindow, saveDevice);
- /*
- • Here you would handle any changes called for when the active window is
- • changed. For example, your menus might be different for one window than
- • another, or you might need to highlight/unhighlight a scrollbar.
- */
- break;
- }
- default: // ••• Consider an unknown window as a fatal error.
- {
- SysBeep(1);
- ExitToShell ();
- break;
- }
- }
- }
-
-
- /*_____________________________________________________________________________
- Do_TEIdle()- not used
- _____________________________________________________________________________*/
-
-
-
-
- void Do_TEIdle (TEHandle theInput)
- {
- // ••• Not necessary for this program. Handles some routine TextEdit housekeeping.
- }
-
-
- /*_____________________________________________________________________________
- Close_Window()- choose the appropriate window closing routine
- _____________________________________________________________________________*/
-
-
-
- void Close_Window (WindowPtr thisWindow)
- /*
- • Note that the system generates a pair of activate/deactivate events
- • whenever a new window comes to the fore. Closing a window, however,
- • will only generate an activate event, since there is no window to
- • deactivate. More complex programs than this one often do significant
- • housekeeping tasks in their deactivate routines. If your program does this,
- • you may need to do the following. First, hide the window you intend to close,
- • bringing your next window to the fore. This generates a pair of
- • activate/deactivate events. Call WaitNextEvent twice with the mask
- • activMask so you only retrieve activate/deactivate events, and process
- • them immediately. Now you can dispose of the window you are closing.
- •
- • See the note about reference constants (RefCon's) in the function
- • Activate_Window() above to understand the use of GetWRefCon() below.
- */
- {
- switch (GetWRefCon(thisWindow))
- {
- case ResID_AboutMST: { Close_AboutMST(); break; }
- case ResID_PeriodicChart: { Close_PeriodicChart(); break; }
- case ResID_Elements: { Close_Elements(); break; }
- }
- }
-
-
- /*_____________________________________________________________________________
- Do_Window()- choose the appropriate routine to handle
- an event in the window's content region
- _____________________________________________________________________________*/
-
-
-
- void Do_Window (WindowPtr thisWindow,EventRecord *thisEvent)
- {
- GDHandle saveDevice;
- CGrafPtr saveCGrafPtr;
-
- GetGWorld (&saveCGrafPtr,&saveDevice);
- SetGWorld ((CGrafPtr)thisWindow,saveDevice);
- /*
- • See the note about reference constants (RefCon's) in the function
- • Activate_Window() above to understand the use of GetWRefCon() below.
- */
-
- switch (GetWRefCon(thisWindow))
- {
- case ResID_AboutMST: { Do_AboutMST (thisEvent); break; }
- case ResID_PeriodicChart: { Do_PeriodicChart (thisEvent); break; }
- case ResID_Elements: { Do_Elements (thisEvent); break; }
- }
- SetGWorld (saveCGrafPtr,saveDevice);
- }
-
- /*_____________________________________________________________________________
- Do_Key()- handle a key event
- _____________________________________________________________________________*/
-
-
- void Do_Key (WindowPtr thisWindow,EventRecord *thisEvent)
- {
- long testKey,keyCode,loop1;
-
- if ((thisEvent->modifiers & cmdKey) == 0)
- {
- testKey = BitAnd (thisEvent->message,charCodeMask); /*leftover line from another program*/
- keyCode = BitAnd (thisEvent->message,keyCodeMask);
- keyCode /= 256;
- if (keyCode==53)
- {
- switch (GetWRefCon(thisWindow))
- {
- case ResID_AboutMST: { Close_AboutMST (); break; }
- case ResID_PeriodicChart: { Close_PeriodicChart (); break; }
- case ResID_Elements: { Close_Elements (); break; }
- }
- }
- }
- }
-
- /*_____________________________________________________________________________
- Update_Window()- choose the appropriate update routine
- _____________________________________________________________________________*/
-
-
- void Update_Window (EventRecord *thisEvent)
- {
- WindowPtr thisWindow;
-
- thisWindow = (WindowPtr)thisEvent->message;
- /*
- • See the note about reference constants (RefCon's) in the function
- • Activate_Window() above to understand the use of GetWRefCon() below.
- */
- switch (GetWRefCon(thisWindow))
- {
- case ResID_AboutMST: { UpDate_AboutMST(); break; }
- case ResID_PeriodicChart: { UpDate_PeriodicChart(); break; }
- case ResID_Elements: { UpDate_Elements(); break; }
- }
- }
-